﻿using System.Windows.Controls;
using System.Windows.Navigation;
using GalaSoft.MvvmLight;
using Mal.Balades.Admin.Converters;
using Mal.Balades.Admin.ViewModels;
using Mal.Balades.Admin.ViewModels.VisitViewModels.Edit;

namespace Mal.Balades.Admin.Views.VisitViews.Edit
{
    public partial class Main : Page
    {
        public Main()
        {
            InitializeComponent();

           
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (this.DataContext is PageViewModelBase)
            {
                ViewModelViewConverter.UnregisterAll();
                ViewModelViewConverter.Register(typeof(MainTabViewModel), typeof( VisitTab));
                ViewModelViewConverter.Register(typeof(InformationsTabViewModel), typeof( InformationsTab));
                ViewModelViewConverter.Register(typeof(MapTabViewModel), typeof( MapTab));
                ViewModelViewConverter.Register(typeof(PicturesTabViewModel), typeof( PicturesTab));

                ((PageViewModelBase)this.DataContext).NavigationContext = this.NavigationContext;
                ((PageViewModelBase)this.DataContext).OnNavigate();
            }
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            if (this.DataContext is ViewModelBase)
            {
                ((PageViewModelBase)this.DataContext).Cleanup();
            }
        }

    }
}
